package org.javaweb.cms_web.service;

import org.javaweb.cms_web.mapper.FeedbackMapper;
import org.javaweb.cms_web.model.Feedback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;

    // 获取所有反馈（支持搜索和筛选）
    public List<Feedback> getFeedbacksWithFilters(String searchKeyword, String statusFilter, String timeFilter) {
        return feedbackMapper.findFeedbacksWithFilters(searchKeyword, statusFilter, timeFilter);
    }
    // 获取所有反馈列表
    public List<Feedback> getAllFeedbacks() {
        return feedbackMapper.findAllFeedbacks();
    }

    // 获取单条反馈详情
    public Feedback getFeedbackById(Integer feedbackId) {
        return feedbackMapper.findById(feedbackId);
    }

    // 回复反馈并更新状态
    public boolean replyToFeedback(Integer feedbackId, String replyContent) {
        // 设置反馈为已处理（status = 1）
        return feedbackMapper.updateFeedbackStatus(feedbackId, 1, replyContent) > 0;
    }

    // 关闭反馈
    public boolean closeFeedback(Integer feedbackId) {
        return feedbackMapper.updateFeedbackStatus2(feedbackId, 2)>0;  // 状态 2 表示关闭
    }
}
